<template>
  <div class="ele-Insurance pd30">
    <div class="panelWrap in-contatiner">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>电梯投保管理</div>
      </div>
      <div class="ele-input m-t-20 flex">
        <el-input v-model="companyName" class="m-l-20 m-r-20" placeholder="请输入保险公司名称" />
        <div>
          <el-select v-model="inValue" placeholder="请选择险种" class="m-r-20">
            <el-option
              v-for="item in radioList"
              :key="item.id"
              :label="item.itemName"
              :value="item.id"
            />
          </el-select>
          <el-button type="primary" @click="getInsuranceList">查询</el-button>
        </div>
      </div>
      <el-divider class="divider" />
      <div class="ele-info m-t-60 flex flexdc">
        <div class="flex flexdc">
          <div class="in-image flex m-b-20">
            <i v-for="item in radioList" :key="item.id" :class="`radio-${item.companyId} co-radio m-b-20`" />
          </div>
          <el-radio-group v-model="radio" class="in-group flex">
            <el-radio v-for="item in radioList" :key="item.id" class="in-radio" :label="item.companyId" @change="handleChangeRadio">
              {{ item.companyName }}
            </el-radio>
          </el-radio-group>
        </div>
        <div class="m-t-80 flexcenter">
          <el-button type="primary" class="in-btn" @click="handleBuy">购 买</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

import { insurQueryList } from '@/api/maintenance/miInsurance'
import { showNotice } from '@/utils/toolclass'

export default {
  data() {
    return {
      radio: 1,
      inValue: '',
      companyName: '',
      radioList: [],
      currentValue: ''
    }
  },
  created() {
    this.$storage.set('upUrl', JSON.stringify({ 'path': '/maInsurance/eleInsurance' }))
  },
  mounted() {
    this.getInsuranceList()
  },
  methods: {
    getInsuranceList() {
      insurQueryList().then(res => {
        // console.log(res)
        if (res.code === '000000') {
          this.radioList = res.data
        } else {
          // showNotice('error', '提示', res.msg)
        }
      })
    },
    handleChangeRadio(val) {
      this.currentValue = val
    },
    handleBuy() {
      this.cuValue = this.currentValue === '' ? this.radio : this.currentValue
      this.radioList.filter(item => {
        if (item.companyId === this.cuValue) {
          var a = document.createElement('a')
          a.setAttribute('href', item.companyUrl)
          a.setAttribute('target', '_blank')
          a.click()
        }
      })
    }
  }
}
</script>

<style lang="scss">
.ele-Insurance {
  .in-contatiner {
    min-height: 800px;
    .in-group {
      justify-content: space-around;
      .in-radio {
        // width: 200px;
      }
    }
    .in-btn {
      width: 100px;
    }
    .in-image {
      width: 100%;
      height: 100px;
      justify-content: space-around;
    }
    .co-radio {
      width: 100px;
      height: 100px;
      border: 1px solid #eeeeee;
      border-radius: 5px;
    }
    .radio-1 {
      background: url('~@/assets/insurance/zgpa.jpg') no-repeat;
      background-size: 100% 100%;
    }
    .radio-2 {
      background: url('~@/assets/insurance/zgrs.jpg') no-repeat;
      background-size: 100% 100%;
    }
    .radio-3 {
      background: url('~@/assets/insurance/tpy.jpg') no-repeat;
      background-size: 100% 100%;
    }
    .radio-4 {
      background: url('~@/assets/insurance/zgrm.jpg') no-repeat;
      background-size: 100% 100%;
    }
  }
}
</style>
